<?php

namespace App\Http\Controllers\Web;

use App\Http\Controllers\Controller;
use App\Models\Channels;
use App\Models\GameChannel;
use App\Models\GameLoginConfig;
use App\Models\Games;
use App\Services\ChannelService;
use App\Services\GameChannelService;
use App\Services\GameLoginService;
use App\Services\WanSdk\WanSdkService;
use Illuminate\Http\Request;

class WanJuheController extends Controller
{
    // 入口
    public function index(Request $request, $game_id, $game_channel_id)
    {
        $params            = $request->all();
        $game              = Games::where('game_id', $game_id)->first()->toArray();
        $game_channel      = GameChannelService::getInstance()->get($game_channel_id);
        $channel           = Channels::where('channel', $game_channel['channel'])->first();
        $game_login_config = GameLoginService::getInstance()->get($game_id);
        $is_wechat         = WanSdkService::getInstance()->isWechatUa() == true?1:0;
        $is_phone          = WanSdkService::getInstance()->isPhone()    == true?1:0;
        $flag              = ucfirst($channel['channel_flag']);
        $vue_component     = "WanJuhe{$flag}";

        $blade = "wan_juhe.{$channel['channel_flag']}";
        return view($blade, [
            'query'             => $params,
            'game'              => $game,
            'game_channel'      => $game_channel,
            'channel'           => $channel,
            'game_login_config' => $game_login_config,
            'vue_component'     => $vue_component,
            'is_wechat'         => $is_wechat,
            'is_phone'          => $is_phone,
        ]);
    }
}
